home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / inventor / SpaceballViewer / SvManipList.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  6.5 KB  |  239 lines

  1. /*
  2.  * Copyright (c) 1990-1992, 1994 Silicon Graphics, Inc.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that the name of Silicon Graphics may not be used in any advertising or
  7.  * publicity relating to the software without the specific, prior written
  8.  * permission of Silicon Graphics.
  9.  *
  10.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  11.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  12.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  13.  *
  14.  * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  15.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
  17.  * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  */
  20. /*
  21.  * Copyright (C) 1990,91,92   Silicon Graphics, Inc.
  22.  *
  23.  * 
  24.  _______________________________________________________________________
  25.  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
  26.  |
  27.  |   $Revision: 1.1004 $
  28.  |
  29.  |   Classes:    SvManipList
  30.  |
  31.  |   Author(s):    David Mott
  32.  |
  33.  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
  34.  _______________________________________________________________________
  35.  */
  36.  
  37. #include <Inventor/SbPList.h>
  38. #include <Inventor/SoPath.h>
  39. #include <Inventor/nodes/SoGroup.h>
  40. #include <Inventor/manips/SoTransformManip.h>
  41. #include "SvManipList.h"
  42.  
  43.  
  44. typedef struct SvPathManipStuff {
  45.     SoPath         *selectionPath;
  46.     SoTransformManip *manip;
  47.     SoPath           *xfPath;
  48. } SvPathManipStuff;
  49.  
  50. ////////////////////////////////////////////////////////////////////////
  51. //
  52. // Constructor
  53. //
  54. // Use: public
  55. SvManipList::SvManipList()
  56. //
  57. ////////////////////////////////////////////////////////////////////////
  58. {
  59.     list = new SbPList;
  60. }
  61.  
  62. ////////////////////////////////////////////////////////////////////////
  63. //
  64. // Destructor
  65. //
  66. // Use: public
  67. SvManipList::~SvManipList()
  68. //
  69. ////////////////////////////////////////////////////////////////////////
  70. {
  71.     delete list;
  72. }
  73.  
  74. ////////////////////////////////////////////////////////////////////////
  75. //
  76. // Use: public
  77. int
  78. SvManipList::getLength() const
  79. //
  80. ////////////////////////////////////////////////////////////////////////
  81. {
  82.     return list->getLength();
  83. }
  84.  
  85. ////////////////////////////////////////////////////////////////////////
  86. //
  87. // Append adds the selectionPath/manip/xfPath stuff to the list.
  88. // This ref()'s both the paths and the manip.
  89. //
  90. // Use: public
  91. void
  92. SvManipList::append(SoPath *selectionP, SoTransformManip *m, 
  93.             SoPath *xfP )
  94. //
  95. ////////////////////////////////////////////////////////////////////////
  96. {
  97.     SvPathManipStuff *stuff = new SvPathManipStuff;
  98.     
  99.     stuff->selectionPath = selectionP;
  100.     stuff->manip = m;
  101.     stuff->xfPath = xfP;
  102.     selectionP->ref();
  103.     m->ref();
  104.     xfP->ref();
  105.     
  106.     list->append(stuff);
  107. }
  108.  
  109. ////////////////////////////////////////////////////////////////////////
  110. //
  111. // Find locates the first selectionPath/manip/xfPath stuff whose 
  112. // selectionPath is p, and returns the index in the list of that stuff.
  113. //
  114. // Use: public
  115. int
  116. SvManipList::find(const SoPath *p) const
  117. //
  118. ////////////////////////////////////////////////////////////////////////
  119. {
  120.     int which = -1;
  121.     
  122.     for (int i = 0; (i < list->getLength()) && (which == -1); i++) {
  123.     SvPathManipStuff *stuff = (SvPathManipStuff *) (*list)[i];
  124.     if (*stuff->selectionPath == *p)
  125.         which = i;
  126.     }
  127.     
  128.     return which;
  129. }
  130.  
  131. ////////////////////////////////////////////////////////////////////////
  132. //
  133. // Find locates the first selectionPath/manip/xfPath stuff whose manip is m,
  134. // and returns the index in the list of that stuff.
  135. //
  136. // Use: public
  137. int
  138. SvManipList::find(const SoTransformManip *m) const
  139. //
  140. ////////////////////////////////////////////////////////////////////////
  141. {
  142.     int which = -1;
  143.     
  144.     for (int i = 0; (i < list->getLength()) && (which == -1); i++) {
  145.     SvPathManipStuff *stuff = (SvPathManipStuff *) (*list)[i];
  146.     if (stuff->manip == m)
  147.         which = i;
  148.     }
  149.     
  150.     return which;
  151. }
  152.  
  153. ////////////////////////////////////////////////////////////////////////
  154. //
  155. // findByXfPath locates the first selectionPath/manip/xfPath stuff whose 
  156. // xfPath is p, and returns the index in the list of that stuff.
  157. //
  158. // Use: public
  159. int
  160. SvManipList::findByXfPath(const SoPath *p) const
  161. //
  162. ////////////////////////////////////////////////////////////////////////
  163. {
  164.     int which = -1;
  165.     
  166.     for (int i = 0; (i < list->getLength()) && (which == -1); i++) {
  167.     SvPathManipStuff *stuff = (SvPathManipStuff *) (*list)[i];
  168.     if (*stuff->xfPath == *p)
  169.         which = i;
  170.     }
  171.     
  172.     return which;
  173. }
  174.  
  175. ////////////////////////////////////////////////////////////////////////
  176. //
  177. // Remove removes the selectionPath/manip/xfPath stuff specified by 
  178. // which index from the list. This unref()'s both paths and the manip.
  179. //
  180. // Use: public
  181. void
  182. SvManipList::remove(int which)
  183. //
  184. ////////////////////////////////////////////////////////////////////////
  185. {
  186.     SvPathManipStuff *stuff = (SvPathManipStuff *) (*list)[which];
  187.     
  188.     stuff->selectionPath->unref();
  189.     stuff->manip->unref();
  190.     stuff->xfPath->unref();
  191.     
  192.     list->remove(which);
  193. }
  194.  
  195. ////////////////////////////////////////////////////////////////////////
  196. //
  197. // This returns the selectionPath in the selectionPath/manip/xfPath stuff 
  198. // specified by which index.
  199. //
  200. // Use: public
  201. SoPath *
  202. SvManipList::getSelectionPath(int which) const
  203. //
  204. ////////////////////////////////////////////////////////////////////////
  205. {
  206.     SvPathManipStuff *stuff = (SvPathManipStuff *) (*list)[which];
  207.     return (stuff->selectionPath);
  208. }
  209.  
  210. ////////////////////////////////////////////////////////////////////////
  211. //
  212. // This returns the manip in the selectionPath/manip/xfPath stuff 
  213. // specified by which index.
  214. //
  215. // Use: public
  216. SoTransformManip *
  217. SvManipList::getManip(int which) const
  218. //
  219. ////////////////////////////////////////////////////////////////////////
  220. {
  221.     SvPathManipStuff *stuff = (SvPathManipStuff *) (*list)[which];
  222.     return (stuff->manip);
  223. }
  224.  
  225. ////////////////////////////////////////////////////////////////////////
  226. //
  227. // This returns the xfPath of the manip in the 
  228. // selectionPath/manip/xfPath stuff specified by which index.
  229. //
  230. // Use: public
  231. SoPath *
  232. SvManipList::getXfPath(int which) const
  233. //
  234. ////////////////////////////////////////////////////////////////////////
  235. {
  236.     SvPathManipStuff *stuff = (SvPathManipStuff *) (*list)[which];
  237.     return (stuff->xfPath);
  238. }
  239.